<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of shunwan
 *
 * @author dragon.hu add @2016.5.13
 */
require_once 'BaseChannel.php';

//易接（顺玩）
class shunwan implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="M49AZP4Z1D8VJ582NKREXU0L2JRW2D2S"; //易接的同步秘钥
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; //
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("shunwan", $_REQUEST);
		
		$app = $_REQUEST['app'];
		$cbi = $_REQUEST['cbi'];
		$ct = $_REQUEST['ct'];
		$fee = $_REQUEST['fee'];
		$pt = $_REQUEST['pt'];
		$sdk = $_REQUEST['sdk'];
		$ssid = $_REQUEST['ssid'];
		$st = $_REQUEST['st'];
		$tcd = $_REQUEST['tcd'];
		$uid = $_REQUEST['uid'];
		$ver = $_REQUEST['ver'];
		$sign = $_REQUEST['sign'];
		
		$mysign = "app=".$app."&cbi=".$cbi."&ct=".$ct."&fee=".$fee."&pt=".$pt."&sdk=".$sdk.
		"&ssid=".$ssid."&st=".$st."&tcd=".$tcd."&uid=".$uid."&ver=".$ver.$paymentKey;
		
		if($sign == md5($mysign))  
		{ //验证通过
			 $tmpstatus = STATUS_SUCCESS;
			 if ($st != 1)
			 	$tmpstatus = STATUS_FAILD;
			//进行发货
			if(false == $orderLog->recordOrder($tmpstatus, $fee/100, $cbi, "yijie", $platform,$ssid))
			{
				$ret="ERROR";
				$orderLog->log("shunwan",array("order"=>$cbi,"money"=>$fee,"serverresult"=>"faild"));
			}else 
			{
				//支付成功
				$ret="SUCCESS";
				$orderLog->log("shunwan",array("order"=>$cbi,"money"=>$fee,"serverresult"=>"success"));
			}
			 
		} else {
			//"$sig验证失败"
			$orderLog->log("shunwan","  order:$cbi  sign error sign:$sign mysign:$mysign");
			$ret="ERROR";
		}
		return $ret;
	}
	
}